#include "Cipher.h"

CaeserCipher::CaeserCipher() {};

std::string CaeserCipher::encrypt(const std::string& x) {
	std::string result = x;
	for (size_t i = 0; i < x.size(); i++) {
		result[i] = x[i] + 3;
	}
	return result;
};

std::string CaeserCipher::decrypt(const std::string& x) {
	std::string result = x;
	for (size_t i = 0; i < x.size(); i++) {
		result[i] = x[i] - 3;
	}
	return result;
};

ReverseCipher::ReverseCipher() {};

std::string ReverseCipher::encrypt(const std::string& x) {
	std::string result = x;
	for (size_t i = 0; i < x.size(); i++) {
		result[i] = 'z' - (x[i] - 97);
	}
	return result;
};
std::string ReverseCipher::decrypt(const std::string& x) {
	std::string result = x;
	for (size_t i = 0; i < x.size(); i++) {
		result[i] = 'z' - (x[i] - 97);
	}
	return result;
};

//------------------------------------------
// tests for Cipher
//------------------------------------------
static void testCaeserCipher() {
	CaeserCipher cip;
	std::string s = "abc";
	std::string result = cip.encrypt(s);
	ASSERT("def" == result);
	std::string result2 = cip.decrypt(result);
	ASSERT(s == result2);
}

static void testReverseCipher() {
	ReverseCipher rci;
	std::string s = "abczyx";
	std::string result = rci.encrypt(s);
	std::cout << "result = " << result << std::endl;
	ASSERT("zyxabc" == result);
	std::string result2 = rci.decrypt(result);
	std::cout << "result2 = " << result2 << std::endl;
	ASSERT(s == result2);
}

void testCipher() {
    TEST(testCaeserCipher);
    TEST(testReverseCipher);
}